﻿#pragma once

#include "Const.h"

// 格
typedef struct Grid {
    BOOL mUsed; // 使用则为 TRUE，否则为 FALSE
} Grid;

// 带颜色的格
typedef struct ColorGrid {
    BOOL mUsed;         // 使用则为 TRUE，否则为 FALSE
    COLORREF mColor;    // 颜色
} ColorGrid;

// 方块的形状
typedef enum Shape {
    ONE,    // 形状1
    TWO,    // 形状2
    THREE,  // 形状3
    FOUR    // 形状4
} Shape;

typedef struct Block Block;

typedef void (*BlockDraw)(Block*);
typedef void (*BlockEnterGameboard)(Block*, HWND, HDC);
typedef void (*BlockEnterPreview)(Block*, HDC);
typedef void (*BlockErase)(Block*);
typedef void (*BlockEraseRect)(Block*, RECT*);
typedef int (*BlockGetBottom)(Block*);
typedef int (*BlockGetTop)(Block*);
typedef void(*BlockHandleCannotMoveDown)(Block*);
typedef BOOL (*BlockMoveDown)(Block*);
typedef void (*BlockMoveLeft)(Block*);
typedef void (*BlockMoveRight)(Block*);
typedef void (*BlockTransform)(Block*);

// 方块
struct Block {
    Grid mBlocks[BLOCK_GRID_COUNT_V][BLOCK_GRID_COUNT_H];   // 方块数据
    COLORREF mColor;    // 颜色
    HDC mDrawer;        // 绘图者
    HWND mGameBoard;    // 游戏区域
    int mLine;          // 当前所在列(左)
    int mRow;           // 当前所在行(上)
    Shape mShape;       // 形状

    BlockDraw draw;
    BlockEnterGameboard enterGameBoard;
    BlockEnterPreview enterPreview;
    BlockErase erase;
    BlockEraseRect eraseRect;
    BlockGetBottom getBottom;
    BlockGetTop getTop;
    BlockHandleCannotMoveDown handleCannotMoveDown;
    BlockMoveDown moveDown;
    BlockMoveLeft moveLeft;
    BlockMoveRight moveRight;
    BlockTransform transform;
};

Block* New_Block();
void Block_Draw(Block*);
void Block_EnterGameboard(Block*, HWND, HDC);
void Block_EnterPreview(Block*, HDC);
void Block_EraseRect(Block*, RECT*);
BOOL Block_MoveDown(Block*);
void Block_MoveLeft(Block*);
void Block_MoveRight(Block*);
